package com.hxgis.common.utils;

import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.Days;
import org.joda.time.Hours;
import org.joda.time.format.DateTimeFormat;
import org.joda.time.format.DateTimeFormatter;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class TimeUtil {

	public final static String FORMATOR_Y = "yyyy";
	public final static String FORMATOR_M = "MM";
	public final static String FORMATOR_D = "dd";
	public final static String FORMATOR_H = "HH";
	public final static String FORMATOR_YYMMDDHH = "yyMMddHH";
	public final static String FORMATOR_YM = "yyyyMM";
	public final static String FORMATOR_YMD = "yyyyMMdd";
	public final static String FORMATOR_YMDH = "yyyyMMddHH";
	public final static String FORMATOR_YMDHM = "yyyyMMddHHmm";
	public final static String FORMATOR_YMDHMS = "yyyyMMddHHmmss";
	public final static String WEB_FORMATOR_YMD = "yyyy-MM-dd";
	public final static String WEB_FORMATOR_YMDH = "yyyy-MM-dd HH";
	public final static String WEB_FORMATOR_YMDHM = "yyyy-MM-dd HH:mm";
	public final static String WEB_FORMATOR_YMDHMS = "yyyy-MM-dd HH:mm:ss";
	public final static String ZN_FORMATOR_YMD = "yyyy年MM月dd日";
	public final static String ZN_FORMATOR_YMDH = "yyyy年MM月dd日 HH时";
	public final static String ZN_FORMATOR_MDH = "MM月dd日HH时";

	private final static SimpleDateFormat longSdf = new SimpleDateFormat(FORMATOR_YMD);

	/**
	 * 根据条件获取当前时间
	 * @param formatStr 格式化字符串
	 * @return
	 */
	public static String currentTime(String formatStr) {
		String currentHour = "";
		DateTime dt = new DateTime();
		DateTimeFormatter dtf = DateTimeFormat.forPattern(formatStr);
		currentHour = dt.toString(dtf);
		return currentHour;
	}

	/**
	 * 不同格式时间字符串之间相互转换
	 * @param dataStr
	 * @param oldfrt
	 * @param newfrt
	 * @return
	 */
	public static String changeStyle(String dataStr,String oldfrt,String newfrt){
		DateTimeFormatter oldtf = DateTimeFormat.forPattern(oldfrt);
		DateTimeFormatter newtf = DateTimeFormat.forPattern(newfrt);
		DateTime day = oldtf.parseDateTime(dataStr);
		return day.toString(newtf);
	}

	/**
	 * 计算N小时前时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String preMonth(String dataStr, int months) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YM);
		DateTime month = dtf.parseDateTime(dataStr);
		month = month.minusMonths(months);
		return month.toString(dtf);
	}

	/**
	 * 计算N天后日期
	 * @param dataStr 日期字符串 默认为yyyyMMdd
	 * @param days 需要计算的天数
	 * @return
	 */
	public static String nextDay(String dataStr, int days) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMD);
		DateTime day = dtf.parseDateTime(dataStr);
		day = day.plusDays(days);
		return day.toString(dtf);
	}

	/**
	 * 计算N天后日期
	 * @param dataStr 日期字符串 默认为yyyyMMdd
	 * @param days 需要计算的天数
	 * @return
	 */
	public static String nextDay(String dataStr, int days,String formatter) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(formatter);
		DateTime day = dtf.parseDateTime(dataStr);
		day = day.plusDays(days);
		return day.toString(dtf);
	}

	/**
	 * 计算N天前日期
	 * @param dataStr 日期字符串 默认为yyyyMMdd
	 * @param days	需要计算的天数
	 * @return
	 */
	public static String preDay(String dataStr, int days) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMD);
		DateTime day = dtf.parseDateTime(dataStr);
		day = day.minusDays(days);
		return day.toString(dtf);
	}

	/**
	 * 计算N天前日期
	 * @param dataStr 日期字符串 默认为yyyyMMdd
	 * @param days	需要计算的天数
	 * @return
	 */
	public static String preDay(String dataStr, int days,String formatter) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(formatter);
		DateTime day = dtf.parseDateTime(dataStr);
		day = day.minusDays(days);
		return day.toString(dtf);
	}

	/**
	 * 计算N小时前时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String preHour(String dataStr, int hours) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMDH);
		DateTime hour = dtf.parseDateTime(dataStr);
		hour = hour.minusHours(hours);
		return hour.toString(dtf);
	}

	/**
	 * 计算N小时前时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String preHour(String dataStr, int hours, String inputFmt, String outputFmt) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(inputFmt);
		DateTimeFormatter outDtf = DateTimeFormat.forPattern(outputFmt);
		DateTime hour = dtf.parseDateTime(dataStr);
		hour = hour.minusHours(hours);

		return hour.toString(outDtf);
	}

	/**
	 * 计算N小时后时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String nextHour(String dataStr, int hours) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMDH);
		DateTime hour = dtf.parseDateTime(dataStr);
		hour = hour.plusHours(hours);
		return hour.toString(dtf);
	}

	/**
	 * 计算N小时后时间
	 * @param dataStr 时间字符串
	 * @return
	 */
	public static String nextHour(String dataStr, int hours,String fmt) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(fmt);
		DateTime hour = dtf.parseDateTime(dataStr);
		hour = hour.plusHours(hours);
		return hour.toString(dtf);
	}

	/**
	 * 计算N小时后时间
	 * @param dataStr 时间字符串
	 * @return
	 */
	public static String nextHour(String dataStr, int hours, String inputFmt, String outputFmt) {
		DateTimeFormatter dtf = DateTimeFormat.forPattern(inputFmt);
		DateTimeFormatter outDtf = DateTimeFormat.forPattern(outputFmt);
		DateTime hour = dtf.parseDateTime(dataStr);
		hour = hour.plusHours(hours);
		return hour.toString(outDtf);
	}
	/**
	 * 计算N秒钟前时间
	 * @param t
	 * @param seconds
	 * @return 时间字符串 默认为yyyyMMddHHmmss
	 */
	public  static String nextSecond(DateTime t, int seconds){
		t = t.minusSeconds(seconds);
		return t.toString(DateTimeFormat.forPattern(FORMATOR_YMDHMS));
	}

	/**
	 * 北京时间转世界时间
	 * @param dataStr 时间字符串 默认为 yyyyMMddHH
	 * @return
	 */
	public static String BJTimeToUTC(String dataStr,String formate) {
		DateTime utc = null;
		DateTimeFormatter dtf = null;
		try {
			dtf = DateTimeFormat.forPattern(formate).withZoneUTC();
			DateTime dt = dtf.parseDateTime(dataStr);
			utc = dt.minusHours(8);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return utc.toString(dtf);
	}

	/**
	 * 北京时间转世界时间
	 * @param dataStr 时间字符串 默认为 yyyyMMddHH
	 * @return
	 */
	public static String BJTimeToUTC(String dataStr) {
		DateTime utc = null;
		DateTimeFormatter dtf = null;
		try {
			dtf = DateTimeFormat.forPattern(FORMATOR_YMDH).withZoneUTC();
			DateTime dt = dtf.parseDateTime(dataStr);
			utc = dt.minusHours(8);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return utc.toString(dtf);
	}

	/**
	 * 世界时间转北京时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String UTCToBJTime(String dataStr) {
		String end = dataStr.substring(10);
		dataStr = dataStr.substring(0, 10);
		DateTime utc = null;
		DateTimeFormatter dtf = null;
		try {
			dtf = DateTimeFormat.forPattern(FORMATOR_YMDH).withZoneUTC();
			DateTime dt = dtf.parseDateTime(dataStr);
			utc = dt.plusHours(8);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return utc.toString(dtf) + end;
	}

	/*
	 * 世界时间转北京时间
	 * @param dataStr 时间字符串 默认为yyyyMMddHH
	 * @return
	 */
	public static String UTCToBJTime(String dataStr,String fmt) {
		DateTime utc = null;
		DateTimeFormatter dtf = null;
		try {
			dtf = DateTimeFormat.forPattern(fmt).withZoneUTC();
			DateTime dt = dtf.parseDateTime(dataStr);
			utc = dt.plusHours(8);
		} catch (Exception e) {
			e.printStackTrace();
		}

		return utc.toString(dtf);
	}

	/**
	 * 获取国际时间
	 * @param formatStr
	 * @return
	 */
	public static String getGMTime(String formatStr){
		String time = "";
		DateTimeZone zone= DateTimeZone.forID("GMT");
		DateTime dt = new DateTime(zone);
		DateTimeFormatter dtf = DateTimeFormat.forPattern(formatStr);
		time = dt.toString(dtf);
		return time;
	}

	/**
	 * 获取北京时间
	 * @param formatStr
	 * @return
	 */
	public static String getBJTime(String formatStr){
		String time = "";
		DateTimeZone zone= DateTimeZone.forID("Asia/Shanghai");
		DateTime dt = new DateTime(zone);
		DateTimeFormatter dtf = DateTimeFormat.forPattern(formatStr);
		time = dt.toString(dtf);
		return time;
	}

	/**
	 * 日期格式转换
	 * @param time
	 * @param fromfmt
	 * @param tofmt
	 * @return
	 */
	public static String format(String time,String fromfmt,String tofmt){
		DateTimeFormatter fm = DateTimeFormat.forPattern(fromfmt);
		DateTimeFormatter to = DateTimeFormat.forPattern(tofmt);
		DateTime dt = fm.parseDateTime(time);
		return dt.toString(to);
	}

	public static String format(Date time,String tofmt){
		if(time == null){
			return "";
		}
		DateTime dt = new DateTime(time);
		DateTimeFormatter to = DateTimeFormat.forPattern(tofmt);
		return dt.toString(to);
	}

	/**
	 * 获取当前日期 yyyyMMDD
	 * @return
	 */
	public static Date currentDay(){
		Calendar c = Calendar.getInstance();
		return c.getTime();
	}

	public static List<String> getMonthBetweenDateStr(String minDate, String maxDate) throws ParseException {
		List<String> listDate = new ArrayList<String>();
		Calendar startCalendar = Calendar.getInstance();
		Calendar endCalendar = Calendar.getInstance();
		SimpleDateFormat df = new SimpleDateFormat(FORMATOR_YMD);
		Date startDate = df.parse(minDate);
		startCalendar.setTime(startDate);
		Date endDate = df.parse(maxDate);
		endCalendar.setTime(endDate);
		while(true){
			startCalendar.add(Calendar.DAY_OF_MONTH, 1);
			if(startCalendar.getTimeInMillis() < endCalendar.getTimeInMillis()){
				listDate.add(df.format(startCalendar.getTime()));
			}else{
				break;
			}
		}
		return listDate;
	}



	public static String getLastDayOfMonth(int year, int month) {
		 Calendar cal = Calendar.getInstance();
		 cal.clear();

		 cal.set(Calendar.YEAR, year);
		 cal.set(Calendar.MONTH, month-1);
		 cal.set(Calendar.DAY_OF_MONTH,cal.getActualMaximum(cal.DAY_OF_MONTH));

//		int firstDay=cal.getActualMinimum(cal.DAY_OF_MONTH);
//		int lastDay=cal.getActualMaximum(cal.DAY_OF_MONTH);


		return new SimpleDateFormat( FORMATOR_YMD).format(cal.getTime());
	 }

	public static String getFirstDayOfMonth(int year, int month) {
		Calendar cal = Calendar.getInstance();
		cal.clear();
		cal.set(Calendar.YEAR, year);
		cal.set(Calendar.MONTH, month-1);
		cal.set(Calendar.DAY_OF_MONTH,cal.getActualMinimum(cal.DAY_OF_MONTH));
		return new SimpleDateFormat( FORMATOR_YMD).format(cal.getTime());
	}

	public static Date formatStringToDate(String date,String format){
		SimpleDateFormat formatter = new SimpleDateFormat(format);
		try {
			return formatter.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}


	/**
	 * 获取年份组
	 * @param startTime
	 * @param endDate
	 * @return
	 */
	public static Map<String,String> getYears(Date startTime, Date endDate){
		Integer startYear = getYear(startTime);
		Integer endYear = getYear(endDate);
		Map<String,String> yearsMap = new LinkedHashMap<String, String>();
		if (endYear-startYear<=0){
			endYear = startYear;
		}
		for (int i =startYear;i<=endYear;i++){
			yearsMap.put(i+"0101",i+1+"0101");
		}
		return yearsMap;
	}


	public static Calendar getInstance(Date date){
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(date);
		return calendar;
	}

	/**
	 * 获取年份
	 * @param date
	 * @return
	 */
	public static Integer getYear(Date date){
		return getInstance(date).get(Calendar.YEAR);
	}

	/**
	 * 获取月旬 三旬: 上旬1-10日 中旬11-20日 下旬21-31日
	 *
	 * @param date
	 * @return
	 */
	public static int getTenDay(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int i = c.get(Calendar.DAY_OF_MONTH);
		if (i < 11)
			return 1;
		else if (i < 21)
			return 2;
		else
			return 3;
	}

	/**
	 * 本月的结束时间
	 *
	 * @return
	 */
	public static String monthEndTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Date dt = null;
		try {
			c.set(Calendar.DATE, 1);
			c.add(Calendar.MONTH, 1);
			c.add(Calendar.DATE, -1);
			dt = longSdf.parse(longSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format(dt,FORMATOR_YMD);
	}

	/**
	 * 获得本月的开始时间
	 *
	 * @return
	 */
	public static String monthStartTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Date dt = null;
		try {
			c.set(Calendar.DATE, 1);
			dt = longSdf.parse(longSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format(dt,FORMATOR_YMD);
	}

	/**
	 * 本月的结束时间
	 *
	 * @return
	 */
	public static Date getMonthEndTime(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Date dt = null;
		try {
			c.set(Calendar.DATE, 1);
			c.add(Calendar.MONTH, 1);
			c.add(Calendar.DATE, -1);
			dt = longSdf.parse(longSdf.format(c.getTime()));

		} catch (Exception e) {
			e.printStackTrace();
		}
		return dt;
	}

	/**
	 * 获得本月的开始时间
	 *
	 * @return
	 */
	public static Date getMonthStartTime(Date date) {
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		Date dt = null;
		try {
			c.set(Calendar.DATE, 1);
			dt = longSdf.parse(longSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return dt;
	}


	/**
	 * 获取所属旬开始时间
	 *
	 * @param time
	 * @return
	 */
	public static String getTenDayStartTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		int ten = getTenDay(date);
		try {
			if (ten == 1) {
				return format(getMonthStartTime(date),FORMATOR_YMD);
			} else if (ten == 2) {
				SimpleDateFormat df = new SimpleDateFormat("yyyyMM11");
				return format(longSdf.parse(df.format(date)),FORMATOR_YMD);
			} else {
				SimpleDateFormat df = new SimpleDateFormat("yyyyMM21");
				return format(longSdf.parse(df.format(date)),FORMATOR_YMD);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}


	/**
	 * 获取所属旬结束时间
	 *
	 * @param time
	 * @return
	 */
	public static String getTenDayEndTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		int ten = getTenDay(date);
		try {
			if (ten == 1) {
				SimpleDateFormat df = new SimpleDateFormat("yyyyMM10");
				return format(longSdf.parse(df.format(date)),FORMATOR_YMD);
			} else if (ten == 2) {
				SimpleDateFormat df = new SimpleDateFormat("yyyyMM20");
				return format(longSdf.parse(df.format(date)),FORMATOR_YMD);
			} else {
				return format(getMonthEndTime(date),FORMATOR_YMD);
			}
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;


	}




	/**
	 * 当前季度的开始时间
	 *
	 * @return
	 */
	public static String getQuarterStartTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		Date dt = null;
		try {
			if (currentMonth >= 1 && currentMonth <= 3)
				c.set(Calendar.MONTH, 0);
			else if (currentMonth >= 4 && currentMonth <= 6)
				c.set(Calendar.MONTH, 3);
			else if (currentMonth >= 7 && currentMonth <= 9)
				c.set(Calendar.MONTH, 6);
			else if (currentMonth >= 10 && currentMonth <= 12)
				c.set(Calendar.MONTH, 9);
			c.set(Calendar.DATE, 1);
			dt = longSdf.parse(longSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format(dt,FORMATOR_YMD);
	}

	/**
	 * 当前季度的结束时间
	 *
	 * @return
	 */
	public static String getQuarterEndTime(String time) {
		Date date = null;
		try {
			date = longSdf.parse(time);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		Calendar c = Calendar.getInstance();
		c.setTime(date);
		int currentMonth = c.get(Calendar.MONTH) + 1;
		Date dt = null;
		try {
			if (currentMonth >= 1 && currentMonth <= 3) {
				c.set(Calendar.MONTH, 2);
				c.set(Calendar.DATE, 31);
			} else if (currentMonth >= 4 && currentMonth <= 6) {
				c.set(Calendar.MONTH, 5);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 7 && currentMonth <= 9) {
				c.set(Calendar.MONTH, 8);
				c.set(Calendar.DATE, 30);
			} else if (currentMonth >= 10 && currentMonth <= 12) {
				c.set(Calendar.MONTH, 11);
				c.set(Calendar.DATE, 31);
			}
			dt = longSdf.parse(longSdf.format(c.getTime()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return format(dt,FORMATOR_YMD);
	}







	public static void main(String[] args) throws ParseException {
		String startTime = "20180505";
		String endTime = "20200719";
		Integer startYear = Integer.parseInt(startTime.substring(0,4));
		Integer endYear = Integer.parseInt(endTime.substring(0,4));
		for (int i = startYear; i <= endYear; i++){
			// 这里需要处理一下
			if (Objects.equals(startYear,endYear) || Objects.equals(startYear, i) || Objects.equals(endYear,i)){
				if (Objects.equals(startYear,endYear)){
//					tuples.add(Tuple.instance(startTime, endYear + "1231").putTriggerVal("index",2));
					System.out.println(startTime + "---- " + i + "1231");
					continue;
				}
				if (Objects.equals(startYear, i)){
//					tuples.add(Tuple.instance(startYear + "0101", endTime).putTriggerVal("index",2));
					System.out.println(startTime + "---- " + TimeUtil.getLastDayOfMonth(i, 12));
					continue;
				}
				if (Objects.equals(endYear,i)){
//					tuples.add(Tuple.instance(startYear + "0101", endYear + "1231").putTriggerVal("index",2));
					System.out.println(TimeUtil.getFirstDayOfMonth(i, 1) + "---- " + TimeUtil.getLastDayOfMonth(i, 12));
					continue;
				}

			}else {
//				tuples.add(Tuple.instance(startYear + "0101", endYear + "1231").putTriggerVal("index",2));
				System.out.println(i + "0101" + "---- " + i + "1231");
			}
		}


//		for (int i = startYear; i <= endYear; i++){
//			if (Objects.equals(startYear,endYear) || Objects.equals(startYear, i) || Objects.equals(endYear,i)){
//				String stTime = null;
//				String edTime = null;
//				Integer startMonth = null;
//				Integer endMonth = null;
//				if (Objects.equals(startYear,endYear)){
//					stTime = startTime;
//					startMonth = Integer.parseInt(startTime.substring(4,6));
//					endMonth =  Integer.parseInt(endTime.substring(4,6));
//
//					// 循环月
//					get(startTime, endTime, i, stTime, startMonth, endMonth);
//					continue;
//				}
//				if (Objects.equals(startYear, i)){
//					stTime = startTime;
//					startMonth = Integer.parseInt(startTime.substring(4,6));
//					endMonth =  12;
//
//					// 循环月
//					get(startTime, endTime, i, stTime, startMonth, endMonth);
//					continue;
//				}
//				if (Objects.equals(endYear,i)){
//					stTime = endYear + "0101";
//					startMonth = 1;
//					endMonth =  Integer.parseInt(endTime.substring(4,6));
//
//					// 循环月
//					get(startTime, endTime, i, stTime, startMonth, endMonth);
//					continue;
//				}
//			} else {
//					for (int j = 1; j <= 12 ; j++){
//						String firstDayOfMonth = TimeUtil.getFirstDayOfMonth(i, j);
//						String lastDayOfMonth = TimeUtil.getLastDayOfMonth(i, j);
//						System.out.println(firstDayOfMonth +  " ----" +lastDayOfMonth);
//					}
//				}
//			}


		List<String> monthBetweenDateStr1 = TimeUtil.getMonthBetweenDateStr(TimeUtil.preDay("20200101", 1),
				TimeUtil.nextDay("20201231", 1));


		for (int i = 1; i <= 12; i++) {
			System.out.println(getLastDayOfMonth(2019, i));
			System.out.println(getFirstDayOfMonth(2019, i));
		}



		String nowHours = TimeUtil.currentTime(TimeUtil.FORMATOR_YMDH);
		String pre48Hours = TimeUtil.preHour(nowHours, 240);

		String time = TimeUtil.currentTime(TimeUtil.FORMATOR_YMD);
		System.out.println(time.substring(0,4));

		String s = "2.0090621E7";

		System.out.println(new Double(s).intValue());


		System.out.println(nextDay("20080625",5));

//		String time = TimeUtil.currentTime(TimeUtil.FORMATOR_YMD);
//		String preDay = TimeUtil.preDay(time, 1);
//		String preDayOneMonth = TimeUtil.preDay(time, 31);
		List<String> monthBetweenDateStr = getMonthBetweenDateStr(TimeUtil.preDay("20190601",1), nextDay("20190630",1));

		System.out.println(getTenDayEndTime("20190221"));
		System.out.println(getTenDayStartTime("20190221"));
		System.out.println(getQuarterEndTime("20190521"));
		System.out.println(getQuarterStartTime("20190521"));
		System.out.println(monthEndTime("20190621"));
		System.out.println(monthStartTime("20190621"));
//		System.out.println("20190824".substring(0,4));
//
//		System.out.println(getDaysBetween2Date("20120731","20120610"));
//
//
//		System.out.println(getFirstDayOfMonth(2019,12));
//		System.out.println(getLastDayOfMonth(2019,12));
//
//		List<String> monthBetweenDateStr = getMonthBetweenDateStr("20100701", "20100901");
//		monthBetweenDateStr.stream().forEach(x -> {
//			x+="000000";
//			System.out.println(x);
////			System.out.println("++++++" + nextDay(x,1));
//		});
//
//
//		String time = TimeUtil.getGMTime(TimeUtil.FORMATOR_YMD);
//		time = TimeUtil.preDay(time, 2);
//		System.out.println(TimeUtil.isAfter(time, time,TimeUtil.FORMATOR_YMD));
//		System.out.println("世界时间转北京时间："+UTCToBJTime("2019080609"));
//		System.out.println("北京时间转世界时间："+BJTimeToUTC("2014082200"));
//		String aaa  = "2019-08-06 09:00:00";

//		System.out.println("计算前N天："+preDay("20140822", 1));
//		System.out.println("计算后N天："+nextDay("20140822", 1));
//		System.out.println("计算前N小时："+preHour("2014082214", 2));
//		System.out.println("计算后N小时："+nextHour("2014082214", 2));
//		System.out.println("获取当前分钟："+currentTime(FORMATOR_YMDH));
//		System.out.println("获取国际时间："+getGMTime(FORMATOR_YMDH));
//		System.out.println("获取北京时间："+getBJTime(FORMATOR_YMDH));
		// System.out.println(changeDay("2014082110", 1));
		// System.out.println(changeHour("2014082210",5));
		// DateTimeFormatter dft=
		// DateTimeFormat.forPattern(FORMATOR_YMDH).withZoneUTC();
		// int month = dt.getMonthOfYear();//8
		// String month2 = dt.monthOfYear().getAsShortText();//八月
		// String month3 = dt.monthOfYear().getAsString();//8
		// String month4 = dt.monthOfYear().getAsText();//八月
		// String month5 = dt.monthOfYear().getName();//monthOfYear
		// System.out.println(month + "|" + month2 + "|" + month3 + "|" + month4
		// + "|" + month5);
		//
		//
		// DateTime year2013 = dt.withYear(2013);
		// DateTime eighthourslater = dt.plusHours(8);
		// System.out.println(year2013.getYear()+"|"+year2013.getYearOfCentury()+"|"+year2013.getYearOfEra());
		// System.out.println(eighthourslater.hourOfDay().getAsShortText());
		// System.out.println(eighthourslater.hourOfDay().getAsText());


//		String stime = TimeUtil.format(aaa,WEB_FORMATOR_YMDHMS,TimeUtil.FORMATOR_YMDH);
//		System.out.println(stime);
//
//		System.out.println(UTCToBJTime(aaa, WEB_FORMATOR_YMDHMS));
//
//
//		String aaaaaa = "10.5";
//		BigDecimal multiply = new BigDecimal(aaaaaa).multiply(new BigDecimal(10));
//		System.out.println(multiply.intValue());
//		System.out.println(Long.parseLong("20190810"));
	}

	private static void get(String startTime, String endTime, int i, String stTime, Integer startMonth, Integer endMonth) {
		for (int j = startMonth; j <= endMonth; j++) {
			if (Objects.equals(Integer.parseInt(startTime.substring(4,6)),j)){
				System.out.println(stTime +  " ----" + TimeUtil.getLastDayOfMonth(i,j));
			}else if (Objects.equals(Integer.parseInt(endTime.substring(4,6)),j)){
				System.out.println(TimeUtil.getFirstDayOfMonth(i,j) +  " ----" +endTime);
			}else{
				System.out.println(TimeUtil.getFirstDayOfMonth(i,j) +  " ----" +TimeUtil.getLastDayOfMonth(i,j));
			}
		}
	}

	/**
	 * 比较时间大小
	 * @param dt1
	 * @param dt2
	 * @return
	 */
	public static boolean isAfter(String dt1,String dt2){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMDH);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isAfter(dateTime2);
	}

	/**
	 * 比较时间大小
	 * @param dt1
	 * @param dt2
	 * @param fmt
	 * @return
	 */
	public static boolean isAfterOrEqual(String dt1,String dt2,String fmt){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(fmt);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isAfter(dateTime2) || dateTime1.isEqual(dateTime2);
	}

	/**
	 * 比较时间大小
	 * @param dt1
	 * @param dt2
	 * @return
	 */
	public static boolean isAfterOrEqual(String dt1,String dt2){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMDH);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isAfter(dateTime2) || dateTime1.isEqual(dateTime2);
	}

	/**
	 * 比较时间大小
	 * @param dt1
	 * @param dt2
	 * @param fmt
	 * @return
	 */
	public static boolean isAfter(String dt1,String dt2,String fmt){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(fmt);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isAfter(dateTime2) ;
	}

	/**
	 * 比较时间大小 yyyyMMddHH
	 * @param dt1
	 * @param dt2
	 * @return
	 */
	public static boolean isEqual(String dt1,String dt2){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(FORMATOR_YMDH);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isEqual(dateTime2);
	}

	/**
	 * 比较时间大小
	 * @param dt1
	 * @param dt2
	 * @param fmt
	 * @return
	 */
	public static boolean isEqual(String dt1,String dt2,String fmt){
		DateTimeFormatter dtf = DateTimeFormat.forPattern(fmt);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		return dateTime1.isEqual(dateTime2);
	}

	/**
	 * 判断时间差 默认时间格式为yyyymmdd
	 * @param dt1
	 * @param dt2
	 * @return
	 */
	public static int getDaysBetween2Date(String dt1,String dt2){
		int days = 999;
		DateTimeFormatter dtf = DateTimeFormat.forPattern(TimeUtil.FORMATOR_YMD);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		days = Days.daysBetween(dateTime1, dateTime2).getDays();
		return days +1 ;
	}

	/**
	 * 判断时间差 默认时间格式为yyMMddHH
	 * @param dt1
	 * @param dt2
	 * @return
	 */
	public static int getHoursBetween2Date(String dt1,String dt2){
		int hours = 999;
		DateTimeFormatter dtf = DateTimeFormat.forPattern(TimeUtil.FORMATOR_YYMMDDHH);
		DateTime dateTime1 = dtf.parseDateTime(dt1);
		DateTime dateTime2 = dtf.parseDateTime(dt2);
		hours = Hours.hoursBetween(dateTime1,dateTime2).getHours();
		return hours;
	}


	/**
	 * 解析时间
	 * @param timeStr
	 * @param fmt
	 * @return
	 */
	public static DateTime parseTime(String timeStr, String fmt) {
		DateTimeFormatter format = DateTimeFormat.forPattern(fmt);
		return DateTime.parse(timeStr, format);
	}


}
